<?php
$tickets = db_select_all_data_order("tickets"); 
?>
<div id="index_page">	
Page : 
<?php 
// xu ly phan trang
$number_post_page = 4;
$mytransport = "car";

if(isset($_POST) && $_POST != null)
{	
	$mynumber_post_page = $_POST['set_number_post'];
	if($mynumber_post_page!=-1)
		$number_post_page = $mynumber_post_page;	 
	$mytransport		= $_POST['set_transport'];
	
	$_SESSION['set_filter_post']['set_transport'] =	 $mytransport;
	$_SESSION['set_filter_post']['set_number_post'] =	 $number_post_page;
}

if(!isset($_GET['p']))
{
	if(isset($_SESSION['set_filter_post']['set_number_post']) != null)
		$number_post_page = $_SESSION['set_filter_post']['set_number_post'];
	if(isset($_SESSION['set_filter_post']['set_transport']) != null)
		$mytransport = $_SESSION['set_filter_post']['set_transport'];	
		
	$start = 0;
	$end = $number_post_page;
}
else 
{
	if(isset($_SESSION['set_filter_post']['set_number_post']) != null)
		$number_post_page = $_SESSION['set_filter_post']['set_number_post'];
	if(isset($_SESSION['set_filter_post']['set_transport']) != null)
		$mytransport = $_SESSION['set_filter_post']['set_transport'];	
		
	$cp = $_GET['p'];
	$end = $number_post_page*$cp;
	$start = $end - $number_post_page;
}

//print_r($number_post_page);

$tickets = db_select_all_data_where_char("tickets","transport",$mytransport);
$total_post = count($tickets);

$number_page = ceil($total_post/$number_post_page);
if($number_page>1)
{
	for($i=1;$i<=$number_page;$i++)
	{
		if($cp==$i)
		{
		?>
		<a href="<?php bloginfo('home');?>/wp-admin/admin.php?page=tickets-setting&p=<?php echo $i;?>" style="color: red; font-weight: bold;"><?php echo $i;?></a> &nbsp;|&nbsp;
		<?php 	
		}
		else 
		{
		?>
		<a href="<?php bloginfo('home');?>/wp-admin/admin.php?page=tickets-setting&p=<?php echo $i;?>"><?php echo $i;?></a> &nbsp;|&nbsp;
		<?php 	
		}
	}
}
?>
&nbsp;&nbsp;
&nbsp;&nbsp;
<form action="" method="post">
<select name="set_number_post" onchange="this.form.submit();">
	<option value="-1">-Set Number Post-</option>
	<option <?php if($_SESSION['set_filter_post']['set_number_post']==30) echo 'selected="selected"';?> value="3">30</option>
	<option <?php if($_SESSION['set_filter_post']['set_number_post']==40) echo 'selected="selected"';?> value="4">40</option>
	<option <?php if($_SESSION['set_filter_post']['set_number_post']==50) echo 'selected="selected"';?> value="50">50</option>
	<option <?php if($_SESSION['set_filter_post']['set_number_post']==60) echo 'selected="selected"';?> value="6">60</option>
	<option <?php if($_SESSION['set_filter_post']['set_number_post']==80) echo 'selected="selected"';?> value="80">80</option>
	<option <?php if($_SESSION['set_filter_post']['set_number_post']==100) echo 'selected="selected"';?> value="100">100</option>
	<option <?php if($_SESSION['set_filter_post']['set_number_post']==150) echo 'selected="selected"';?> value="150">150</option>	
</select>

<select name="set_transport" onchange="this.form.submit();">
	<option value="-1">-Set Transport -</option>
	
	<option <?php if($_SESSION['set_filter_post']['set_transport']=="car") echo 'selected="selected"';?> value="car">Cars</option>
	<option <?php if($_SESSION['set_filter_post']['set_transport']=="train") echo 'selected="selected"';?>value="train">Trains</option>
	<option <?php if($_SESSION['set_filter_post']['set_transport']=="flight") echo 'selected="selected"';?>value="flight">Flights</option>
</select>	

</form>		
				
				
				<table>						
						<tr class="first-header">
							<td> Customer</td>
							<td> Email </td>
							<td> Transport </td>
							<td> Payment Status </td>
							<td> Date </td>
							<td> Actions </td>				
						</tr> 
						<?php
						$ltickets = db_select_all_data_limit_custom("tickets", $start, $number_post_page,"transport",$mytransport);
						if($ltickets)
						{
							foreach ($ltickets as $value) 
							{
								$customerID = $value->customerID;
								$customers = db_select_data_by_int("customers", "ID", $customerID);
								
								$new = null;
								if(intval($value->state)==0)
									$new = '<img alt="" src="'.get_bloginfo('template_url').'/images/new.jpg"';
							?>
							<tr class="item-second">
								<td><?php echo $customers[0]->customerName;?> <?php echo $new;?></td>
								<td><?php echo $customers[0]->customerEmail;?> </td>
								<td><?php echo $value->transport;?> </td>
								<td><?php echo $value->status;?> </td>
								<td><?php echo $value->date;?> </td>
								<td>								
									<a href="<?php echo $myurl;?>&ticket=<?php echo $value->ID;?>&customer=<?php echo $customerID;?>">View</a> &nbsp;|&nbsp;
									<a href="<?php echo $myurl;?>&del=<?php echo $value->ID;?>&customer=<?php echo $customerID;?>">Delete</a>
								</td>								
							</tr>
							<?php 
							}
						} 
						?>
						
					</table>	
				</div> 